home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 289_01.zip / MOVEIT.C < prev    next >
Text File  |  1993-04-26  |  3KB  |  92 lines

  1. /*-----------------------------------------------------------------------------
  2. MOVEIT.C
  3.  
  4. This file contains a function that verifies a move, updates the current board
  5. to reflect the changes, and displays that board.
  6.  
  7. Revision History
  8. ----------------
  9. Jon Ward     3 Jan 1989    Initial Revision
  10. Jon Ward     7 Jan 1989    Modification to handle NO_MOVE_MASK condition.
  11. -----------------------------------------------------------------------------*/
  12.  
  13. #include "othello.h"
  14.  
  15.  
  16. /*-----------------------------------------------------------------------------
  17. int verify_move_and_update_board (
  18.   move_type move,
  19.   unsigned char player);
  20.  
  21. This function verifies the validity of the move specifiec by the move argument
  22. and, if valid, updates the current board and displays it.
  23.  
  24. Return Value
  25. ------------
  26.       0        move verified and board was updated and displayed.
  27.      -1        move in error - board NOT updated or displayed.
  28. -----------------------------------------------------------------------------*/
  29.  
  30. int verify_move_and_update_board (
  31.   move_type move,            /* move we wish to make */
  32.   unsigned char player)            /* player making the move */
  33. {
  34. int num_affected;            /* # of pieces that changed */
  35. int aff_list [MAX_AFFECTED_PIECES];    /* array for changed pieces */
  36. int disp;                /* displacement of the move */
  37.  
  38. /*------------------------------------------------
  39. Calculate the displacement into the board for the
  40. move being made and get the list of pieces that
  41. will be affected for the first move at or
  42. following that particular move.
  43. ------------------------------------------------*/
  44.  
  45. if (move & NO_MOVE_MASK)    /* if they pass NO_MOVE */
  46.   SET_ROW_COL (move,0,0);    /* start scan at top left cell */
  47.  
  48. disp = &curnt_bd.board [1+GET_ROW(move)][1+GET_COL(move)] -
  49.     &curnt_bd.board [0][0];
  50.  
  51. num_affected = find_move (&curnt_bd, disp, player, aff_list);
  52.  
  53.  
  54. /*---------------------------------------
  55. If no pieces were affected, see if this
  56. is a no move condition.
  57. ---------------------------------------*/
  58.  
  59. if (num_affected == 0)
  60.   {
  61.   if (!(move & NO_MOVE_MASK))
  62.     return (-1);
  63.   }
  64.  
  65.  
  66. /*---------------------------------------
  67. If there was a valid moves, check to see
  68. if it was the one they entered.
  69. ---------------------------------------*/
  70.  
  71. else
  72.   {
  73.   if (aff_list[0] != disp || move & NO_MOVE_MASK)
  74.     return (-1);
  75.  
  76.   handle_changed_pieces (&curnt_bd, aff_list, num_affected, player, 0);
  77.   }
  78.  
  79.  
  80. disp_board (&curnt_bd);
  81.  
  82. if (!(move & NO_MOVE_MASK))
  83.   {
  84.   disp_player_moved_to (player);
  85.   disp_row (GET_ROW (move));
  86.   disp_col (GET_COL (move));
  87.   }
  88.  
  89. return (0);
  90. }
  91.  
  92.